package com.nwcl.basic.service.impl;

import com.nwcl.basic.bo.UserIntegralFlowBO;
import com.nwcl.basic.dao.UserIntegralFlowDao;
import com.nwcl.basic.entity.UserIntegralFlow;
import com.nwcl.basic.service.UserIntegralFlowService;
import com.nwcl.common.utils.BeanUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.math.BigDecimal;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author liguiqin
 * @date 2023/5/26
 */
@Service
public class UserIntegralFlowServiceImpl implements UserIntegralFlowService {
    @Autowired
    private UserIntegralFlowDao userIntegralFlowDao;

    @Override
    public Integer save(UserIntegralFlowBO bo) {
        UserIntegralFlow flow = BeanUtil.copy(bo, UserIntegralFlow.class);
        userIntegralFlowDao.save(flow);
        return flow.getId();
    }

    @Override
    public Map<Integer,UserIntegralFlowBO> mapByOrderIds(List<Integer> orderIds) {
        Map<Integer,UserIntegralFlowBO> map =new HashMap<>();
        List<UserIntegralFlow> list  =userIntegralFlowDao.getIntegralByOrderIds(orderIds);
        if(CollectionUtils.isEmpty(list)){
            return map;
        }
        for(UserIntegralFlow flow:list){
            if(flow.getOrderId()==null || flow.getOrderId()==0){
                continue;
            }
            map.put(flow.getOrderId(),BeanUtil.copy(flow,UserIntegralFlowBO.class));
        }
        return map;
    }
}
